﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Models.Enums;
using 基于WPF的电缆采样数据分析系统.Models.RefWav;
using 基于WPF的电缆采样数据分析系统.MsgEvents;
using 基于WPF的电缆采样数据分析系统.Service;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;
using 基于WPF的电缆采样数据分析系统.Tools.MessagePopupTool;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork
{
    public class SaveReferenceWaveformUCViewModel : BindableBase, IDialogHostAware
    {
        // 主机名
        private const string DialogHostName = "RootDialog";

        /// <summary>
        /// 当前参考波形
        /// </summary>
        public List<ReferenceWaveform> CurrentRefWavformList { get; set; } = new List<ReferenceWaveform>();

        /// <summary>
        /// 发布订阅
        /// </summary>
        private readonly IEventAggregator Aggregator;


        #region 确定
        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void SaveFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogParameters paras = new DialogParameters();
                paras.Add("CurrentRefWavformList", CurrentRefWavformList);
                if (!R1RBtn && !R2RBtn && !R3RBtn && !R4RBtn && !R5RBtn && !R6RBtn && !R7RBtn && !R8RBtn)
                {
                    paras.Add("CurrentRefWavform", RefWavformType.RefWavformNone);
                    MessagePopup.DisplayMessagePopup(LangugeConvertor.GetValue("NoReferenceWaveformIsSelected"));
                    return;
                } else
                {
                    paras.Add("CurrentRefWavform", CurrentRefWavform);
                }
                
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.Yes, paras));
            }
        }
        #endregion

        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 取消方法
        /// </summary>
        private void CancelFun() 
        { 
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }

        #endregion

        /// <summary>
        /// 打开过程中
        /// </summary>
        /// <param name="parameters"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnDialogOpening(IDialogParameters parameters)
        {
            // 初始化波形集合的类型
            InitRefWavListByType();

            // 绑定初始化设置为上次选中的按钮命令
            //InitRBtn();
            
            // 初始化别名信息
            InitNameInfo();

            // 初始化显示按钮
            InitDisplayBtn();

            // 初始化占用信息
            InitOccupyInfo();
        }

        /// <summary>
        /// 构造器
        /// </summary>
        public SaveReferenceWaveformUCViewModel(IEventAggregator _Aggregator)
        {
            Aggregator = _Aggregator;

            // 初始化参考波形集合
            InitSaveReferenceWaveformUC();

            //绑定确定和取消命令
            SaveCommand = new DelegateCommand(SaveFun);
            CancelCommand = new DelegateCommand(CancelFun);

            // 绑定点击波形按钮命令
            WavBtnCmm = new DelegateCommand<string>(WavBtnFun);

            // 绑定是否清除命令
            ClearCmm = new DelegateCommand<string>(ClearFun);

            // 绑定隐藏所有命令
            HiddenAllCommand = new DelegateCommand(HiddenAllFun);

            // 绑定清除所有命令
            ClearAllCommand = new DelegateCommand(ClearAllFun);
        }

        /// <summary>
        /// 初始化参考波形集合
        /// </summary>
        private void InitSaveReferenceWaveformUC()
        {
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
            CurrentRefWavformList.Add(new ReferenceWaveform());
        }


        #region 单选按钮

        /// <summary>
        /// 当前参考波形
        /// </summary>
        public RefWavformType CurrentRefWavform { get; set; }

        /// <summary>
        /// 单选按钮R1
        /// </summary>
        private bool _R1RBtn;

        /// <summary>
        /// 单选按钮R1
        /// </summary>
        public bool R1RBtn
        {
            get { return _R1RBtn; }
            set {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformOne);
                _R1RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R2
        /// </summary>
        private bool _R2RBtn;

        /// <summary>
        /// 单选按钮R2
        /// </summary>
        public bool R2RBtn
        {
            get { return _R2RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformTwo);
                _R2RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R3
        /// </summary>
        private bool _R3RBtn;

        /// <summary>
        /// 单选按钮R3
        /// </summary>
        public bool R3RBtn
        {
            get { return _R3RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformThree);
                _R3RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R4
        /// </summary>
        private bool _R4RBtn;

        /// <summary>
        /// 单选按钮R4
        /// </summary>
        public bool R4RBtn
        {
            get { return _R4RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformFour);
                _R4RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R5
        /// </summary>
        private bool _R5RBtn;

        /// <summary>
        /// 单选按钮R5
        /// </summary>
        public bool R5RBtn
        {
            get { return _R5RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformFive);
                _R5RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R6
        /// </summary>
        private bool _R6RBtn;

        /// <summary>
        /// 单选按钮R6
        /// </summary>
        public bool R6RBtn
        {
            get { return _R6RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformSix);
                _R6RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R7
        /// </summary>
        private bool _R7RBtn;

        /// <summary>
        /// 单选按钮R7
        /// </summary>
        public bool R7RBtn
        {
            get { return _R7RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformSeven);
                _R7RBtn = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 单选按钮R8
        /// </summary>
        private bool _R8RBtn;

        /// <summary>
        /// 单选按钮R8
        /// </summary>
        public bool R8RBtn
        {
            get { return _R8RBtn; }
            set
            {
                if (value)
                    ToggleRBtn(RefWavformType.RefWavformEight);
                _R8RBtn = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 初始化设置为上次选中的按钮
        /// </summary>
        private void InitRBtn()
        {
            switch (GlobalVariableEdit.CurrentRefWav)
            {
                case RefWavformType.RefWavformOne:
                    R1RBtn = true;
                    break;
                case RefWavformType.RefWavformTwo:
                    R2RBtn = true;
                    break;
                case RefWavformType.RefWavformThree:
                    R3RBtn = true;
                    break;
                case RefWavformType.RefWavformFour:
                    R4RBtn = true;
                    break;
                case RefWavformType.RefWavformFive:
                    R5RBtn = true;
                    break;
                case RefWavformType.RefWavformSix:
                    R6RBtn = true;
                    break;
                case RefWavformType.RefWavformSeven:
                    R7RBtn = true;
                    break;
                case RefWavformType.RefWavformEight:
                    R8RBtn = true;
                    break;
            }
        }

        /// <summary>
        /// 切换单选按钮值
        /// </summary>
        private void ToggleRBtn(RefWavformType R)
        {
            CurrentRefWavform = R;
        }
        #endregion


        #region 波形按钮
        /// <summary>
        /// 点击波形按钮命令
        /// </summary>
        public DelegateCommand<string> WavBtnCmm { get; set; }

        /// <summary>
        /// 点击波形按钮方法
        /// </summary>
        private void WavBtnFun(string R)
        {
            switch (R)
            {
                case "R1":
                    ByTypeChanged(RefWavformType.RefWavformOne);
                    break;
                case "R2":
                    ByTypeChanged(RefWavformType.RefWavformTwo);
                    break;
                case "R3":
                    ByTypeChanged(RefWavformType.RefWavformThree);
                    break;
                case "R4":
                    ByTypeChanged(RefWavformType.RefWavformFour);
                    break;
                case "R5":
                    ByTypeChanged(RefWavformType.RefWavformFive);
                    break;
                case "R6":
                    ByTypeChanged(RefWavformType.RefWavformSix);
                    break;
                case "R7":
                    ByTypeChanged(RefWavformType.RefWavformSeven);
                    break;
                case "R8":
                    ByTypeChanged(RefWavformType.RefWavformEight);
                    break;
            }
        }

        /// <summary>
        /// 根据类型改变
        /// </summary>
        /// <param name="R"></param>
        private void ByTypeChanged(RefWavformType R)
        {
            switch (R)
            {
                case RefWavformType.RefWavformOne:
                    R1RBtn = !R1RBtn;
                    if (R1RBtn)
                    {
                        R2RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformTwo:
                    R2RBtn = !R2RBtn;
                    if (R2RBtn)
                    {
                        R1RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformThree:
                    R3RBtn = !R3RBtn;
                    if (R3RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformFour:
                    R4RBtn = !R4RBtn;
                    if (R4RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R3RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformFive:
                    R5RBtn = !R5RBtn;
                    if (R5RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformSix:
                    R6RBtn = !R6RBtn;
                    if (R6RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R7RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformSeven:
                    R7RBtn = !R7RBtn;
                    if (R7RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R8RBtn = false;
                    }
                    break;
                case RefWavformType.RefWavformEight:
                    R8RBtn = !R8RBtn;
                    if (R8RBtn)
                    {
                        R1RBtn = false;
                        R2RBtn = false;
                        R3RBtn = false;
                        R4RBtn = false;
                        R5RBtn = false;
                        R6RBtn = false;
                        R7RBtn = false;
                    }
                    break;

            }
        }

        /// <summary>
        /// 初始化波形集合的类型
        /// </summary>
        private void InitRefWavListByType()
        {
            CurrentRefWavformList[0].R = RefWavformType.RefWavformOne;
            CurrentRefWavformList[1].R = RefWavformType.RefWavformTwo;
            CurrentRefWavformList[2].R = RefWavformType.RefWavformThree;
            CurrentRefWavformList[3].R = RefWavformType.RefWavformFour;
            CurrentRefWavformList[4].R = RefWavformType.RefWavformFive;
            CurrentRefWavformList[5].R = RefWavformType.RefWavformSix;
            CurrentRefWavformList[6].R = RefWavformType.RefWavformSeven;
            CurrentRefWavformList[7].R = RefWavformType.RefWavformEight;
        }
        #endregion


        #region 别名
        /// <summary>
        /// 别名R1
        /// </summary>
        private string _R1Name;

        /// <summary>
        /// 别名R1
        /// </summary>
        public string R1Name
        {
            get { return _R1Name; }
            set {
                if (_R1Name != value)
                    UpdateName(RefWavformType.RefWavformOne, value);
                _R1Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R2
        /// </summary>
        private string _R2Name;

        /// <summary>
        /// 别名R2
        /// </summary>
        public string R2Name
        {
            get { return _R2Name; }
            set
            {
                if (_R2Name != value)
                    UpdateName(RefWavformType.RefWavformTwo, value);
                _R2Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R3
        /// </summary>
        private string _R3Name;

        /// <summary>
        /// 别名R3
        /// </summary>
        public string R3Name
        {
            get { return _R3Name; }
            set
            {
                if (_R3Name != value)
                    UpdateName(RefWavformType.RefWavformThree, value);
                _R3Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R4
        /// </summary>
        private string _R4Name;

        /// <summary>
        /// 别名R4
        /// </summary>
        public string R4Name
        {
            get { return _R4Name; }
            set
            {
                if (_R4Name != value)
                    UpdateName(RefWavformType.RefWavformFour, value);
                _R4Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R5
        /// </summary>
        private string _R5Name;

        /// <summary>
        /// 别名R5
        /// </summary>
        public string R5Name
        {
            get { return _R5Name; }
            set
            {
                if (_R5Name != value)
                    UpdateName(RefWavformType.RefWavformFive, value);
                _R5Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R6
        /// </summary>
        private string _R6Name;

        /// <summary>
        /// 别名R6
        /// </summary>
        public string R6Name
        {
            get { return _R6Name; }
            set
            {
                if (_R6Name != value)
                    UpdateName(RefWavformType.RefWavformSix, value);
                _R6Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R7
        /// </summary>
        private string _R7Name;

        /// <summary>
        /// 别名R7
        /// </summary>
        public string R7Name
        {
            get { return _R7Name; }
            set
            {
                if (_R7Name != value)
                    UpdateName(RefWavformType.RefWavformSeven, value);
                _R7Name = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 别名R8
        /// </summary>
        private string _R8Name;

        /// <summary>
        /// 别名R8
        /// </summary>
        public string R8Name
        {
            get { return _R8Name; }
            set
            {
                if (_R8Name != value)
                    UpdateName(RefWavformType.RefWavformEight, value);
                _R8Name = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始化别名信息
        /// </summary>
        private void InitNameInfo()
        {
            R1Name = GlobalVariableEdit.R1Name;
            R2Name = GlobalVariableEdit.R2Name;
            R3Name = GlobalVariableEdit.R3Name;
            R4Name = GlobalVariableEdit.R4Name;
            R5Name = GlobalVariableEdit.R5Name;
            R6Name = GlobalVariableEdit.R6Name;
            R7Name = GlobalVariableEdit.R7Name;
            R8Name = GlobalVariableEdit.R8Name;
        }

        /// <summary>
        /// 更新别名
        /// </summary>
        /// <param name="R"></param>
        /// <param name="name"></param>
        private void UpdateName(RefWavformType R, string name)
        {
            switch (R)
            {
                case RefWavformType.RefWavformOne:
                    CurrentRefWavformList[0].RName = name;
                    break;
                case RefWavformType.RefWavformTwo:
                    CurrentRefWavformList[1].RName = name;
                    break;
                case RefWavformType.RefWavformThree:
                    CurrentRefWavformList[2].RName = name;
                    break;
                case RefWavformType.RefWavformFour:
                    CurrentRefWavformList[3].RName = name;
                    break;
                case RefWavformType.RefWavformFive:
                    CurrentRefWavformList[4].RName = name;
                    break;
                case RefWavformType.RefWavformSix:
                    CurrentRefWavformList[5].RName = name;
                    break;
                case RefWavformType.RefWavformSeven:
                    CurrentRefWavformList[6].RName = name;
                    break;
                case RefWavformType.RefWavformEight:
                    CurrentRefWavformList[7].RName = name;
                    break;
            }
        }
        #endregion


        #region 是否显示

        /// <summary>
        /// 是否显示R1
        /// </summary>
        private bool _R1Display;

        /// <summary>
        /// 是否显示R1
        /// </summary>
        public bool R1Display
        {
            get { return _R1Display; }
            set {
                if (_R1Display != value)
                    UpdateDisplay(RefWavformType.RefWavformOne, value);
                _R1Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否显示R2
        /// </summary>
        private bool _R2Display;

        /// <summary>
        /// 是否显示R2
        /// </summary>
        public bool R2Display
        {
            get { return _R2Display; }
            set
            {
                if (_R2Display != value)
                    UpdateDisplay(RefWavformType.RefWavformTwo, value);
                _R2Display = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 是否显示R3
        /// </summary>
        private bool _R3Display;

        /// <summary>
        /// 是否显示R3
        /// </summary>
        public bool R3Display
        {
            get { return _R3Display; }
            set
            {
                if (_R3Display != value)
                    UpdateDisplay(RefWavformType.RefWavformThree, value);
                _R3Display = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 是否显示R4
        /// </summary>
        private bool _R4Display;

        /// <summary>
        /// 是否显示R4
        /// </summary>
        public bool R4Display
        {
            get { return _R4Display; }
            set
            {
                if (_R4Display != value)
                    UpdateDisplay(RefWavformType.RefWavformFour, value);
                _R4Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否显示R5
        /// </summary>
        private bool _R5Display;

        /// <summary>
        /// 是否显示R5
        /// </summary>
        public bool R5Display
        {
            get { return _R5Display; }
            set
            {
                if (_R5Display != value)
                    UpdateDisplay(RefWavformType.RefWavformFive, value);
                _R5Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否显示R6
        /// </summary>
        private bool _R6Display;

        /// <summary>
        /// 是否显示R6
        /// </summary>
        public bool R6Display
        {
            get { return _R6Display; }
            set
            {
                if (_R6Display != value)
                    UpdateDisplay(RefWavformType.RefWavformSix, value);
                _R6Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否显示R7
        /// </summary>
        private bool _R7Display;

        /// <summary>
        /// 是否显示R7
        /// </summary>
        public bool R7Display
        {
            get { return _R7Display; }
            set
            {
                if (_R7Display != value)
                    UpdateDisplay(RefWavformType.RefWavformSeven, value);
                _R7Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否显示R8
        /// </summary>
        private bool _R8Display;

        /// <summary>
        /// 是否显示R8
        /// </summary>
        public bool R8Display
        {
            get { return _R8Display; }
            set
            {
                if (_R8Display != value)
                    UpdateDisplay(RefWavformType.RefWavformEight, value);
                _R8Display = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始化显示按钮
        /// </summary>
        private void InitDisplayBtn()
        {
            R1Display = GlobalVariableEdit.R1Display;
            R2Display = GlobalVariableEdit.R2Display;
            R3Display = GlobalVariableEdit.R3Display;
            R4Display = GlobalVariableEdit.R4Display;
            R5Display = GlobalVariableEdit.R5Display;
            R6Display = GlobalVariableEdit.R6Display;
            R7Display = GlobalVariableEdit.R7Display;
            R8Display = GlobalVariableEdit.R8Display;
        }

        /// <summary>
        /// 更新修改按钮
        /// </summary>
        private void UpdateDisplay(RefWavformType R, bool IsDisplay)
        {
            switch (R) {
                case RefWavformType.RefWavformOne:
                    CurrentRefWavformList[0].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformTwo:
                    CurrentRefWavformList[1].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformThree:
                    CurrentRefWavformList[2].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformFour:
                    CurrentRefWavformList[3].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformFive:
                    CurrentRefWavformList[4].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformSix:
                    CurrentRefWavformList[5].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformSeven:
                    CurrentRefWavformList[6].RDisplayStatus = IsDisplay;
                    break;
                case RefWavformType.RefWavformEight:
                    CurrentRefWavformList[7].RDisplayStatus = IsDisplay;
                    break;
            }
        }
        #endregion


        #region 是否占用

        /// <summary>
        /// R1是否被占用
        /// </summary>
        private string _IsOccupyR1 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R1是否被占用
        /// </summary>
        public string IsOccupyR1
        {
            get { return _IsOccupyR1; }
            set { 
                _IsOccupyR1 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R2是否被占用
        /// </summary>
        private string _IsOccupyR2 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R2是否被占用
        /// </summary>
        public string IsOccupyR2
        {
            get { return _IsOccupyR2; }
            set
            {
                _IsOccupyR2 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R3是否被占用
        /// </summary>
        private string _IsOccupyR3 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R3是否被占用
        /// </summary>
        public string IsOccupyR3
        {
            get { return _IsOccupyR3; }
            set
            {
                _IsOccupyR3 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R4是否被占用
        /// </summary>
        private string _IsOccupyR4 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R4是否被占用
        /// </summary>
        public string IsOccupyR4
        {
            get { return _IsOccupyR4; }
            set
            {
                _IsOccupyR4 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R5是否被占用
        /// </summary>
        private string _IsOccupyR5 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R5是否被占用
        /// </summary>
        public string IsOccupyR5
        {
            get { return _IsOccupyR5; }
            set
            {
                _IsOccupyR5 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R6是否被占用
        /// </summary>
        private string _IsOccupyR6 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R6是否被占用
        /// </summary>
        public string IsOccupyR6
        {
            get { return _IsOccupyR6; }
            set
            {
                _IsOccupyR6 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R7是否被占用
        /// </summary>
        private string _IsOccupyR7 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R7是否被占用
        /// </summary>
        public string IsOccupyR7
        {
            get { return _IsOccupyR7; }
            set
            {
                _IsOccupyR7 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// R8是否被占用
        /// </summary>
        private string _IsOccupyR8 = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// R8是否被占用
        /// </summary>
        public string IsOccupyR8
        {
            get { return _IsOccupyR8; }
            set
            {
                _IsOccupyR8 = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始化占用信息
        /// </summary>
        private void InitOccupyInfo()
        {
            if (GlobalVariableEdit.R1WavList != null)
                IsOccupyR1 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R2WavList != null)
                IsOccupyR2 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R3WavList != null)
                IsOccupyR3 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R4WavList != null)
                IsOccupyR4 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R5WavList != null)
                IsOccupyR5 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R6WavList != null)
                IsOccupyR6 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R7WavList != null)
                IsOccupyR7 = LangugeConvertor.GetValue("Occupied");
            if (GlobalVariableEdit.R8WavList != null)
                IsOccupyR8 = LangugeConvertor.GetValue("Occupied");
        }
        #endregion


        #region 是否清除

        /// <summary>
        /// 是否清除命令
        /// </summary>
        public DelegateCommand<string> ClearCmm { get; set; }

        /// <summary>
        /// 是否清除方法
        /// </summary>
        private void ClearFun(string R)
        {
            switch (R)
            {
                case "R1":
                    ByTypeClearWav(RefWavformType.RefWavformOne);
                    break;
                case "R2":
                    ByTypeClearWav(RefWavformType.RefWavformTwo);
                    break;
                case "R3":
                    ByTypeClearWav(RefWavformType.RefWavformThree);
                    break;
                case "R4":
                    ByTypeClearWav(RefWavformType.RefWavformFour);
                    break;
                case "R5":
                    ByTypeClearWav(RefWavformType.RefWavformFive);
                    break;
                case "R6":
                    ByTypeClearWav(RefWavformType.RefWavformSix);
                    break;
                case "R7":
                    ByTypeClearWav(RefWavformType.RefWavformSeven);
                    break;
                case "R8":
                    ByTypeClearWav(RefWavformType.RefWavformEight);
                    break;
            }
        }

        /// <summary>
        /// 清除波形信息
        /// </summary>
        private void ByTypeClearWav(RefWavformType R)
        {
            switch (R)
            {
                case RefWavformType.RefWavformOne:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R1Display = false;
                    GlobalVariableEdit.R1WavList = null;
                    IsOccupyR1 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformTwo:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R2Display = false;
                    GlobalVariableEdit.R2WavList = null;
                    IsOccupyR2 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformThree:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R3Display = false;
                    GlobalVariableEdit.R3WavList = null;
                    IsOccupyR3 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformFour:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R4Display = false;
                    GlobalVariableEdit.R4WavList = null;
                    IsOccupyR4 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformFive:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R5Display = false;
                    GlobalVariableEdit.R5WavList = null;
                    IsOccupyR5 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformSix:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R6Display = false;
                    GlobalVariableEdit.R6WavList = null;
                    IsOccupyR6 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformSeven:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R7Display = false;
                    GlobalVariableEdit.R7WavList = null;
                    IsOccupyR7 = LangugeConvertor.GetValue("Unoccupied");
                    break;
                case RefWavformType.RefWavformEight:
                    RealTimeOscilloscopeViewModel.Instance.HiddenRefWavform(R);
                    RealTimeOscilloscopeViewModel.Instance.R8Display = false;
                    GlobalVariableEdit.R8WavList = null;
                    IsOccupyR8 = LangugeConvertor.GetValue("Unoccupied");
                    break;
            }
        }
        #endregion


        #region 隐藏所有和清除所有
        /// <summary>
        /// 隐藏所有命令
        /// </summary>
        public DelegateCommand HiddenAllCommand { get; set; }

        /// <summary>
        /// 隐藏所有方法
        /// </summary>
        private void HiddenAllFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                GlobalVariableEdit.R1Display = false;
                GlobalVariableEdit.R2Display = false;
                GlobalVariableEdit.R3Display = false;
                GlobalVariableEdit.R4Display = false;
                GlobalVariableEdit.R5Display = false;
                GlobalVariableEdit.R6Display = false;
                GlobalVariableEdit.R7Display = false;
                GlobalVariableEdit.R8Display = false;

                // 更新到通道界面
                Aggregator.GetEvent<MsgSaveRefWavStatus>().Publish();

                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }

        /// <summary>
        /// 清除所有命令
        /// </summary>
        public DelegateCommand ClearAllCommand { get; set; }

        /// <summary>
        /// 清除所有方法
        /// </summary>
        private void ClearAllFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                ByTypeClearWav(RefWavformType.RefWavformOne);
                ByTypeClearWav(RefWavformType.RefWavformTwo);
                ByTypeClearWav(RefWavformType.RefWavformThree);
                ByTypeClearWav(RefWavformType.RefWavformFour);
                ByTypeClearWav(RefWavformType.RefWavformFive);
                ByTypeClearWav(RefWavformType.RefWavformSix);
                ByTypeClearWav(RefWavformType.RefWavformSeven);
                ByTypeClearWav(RefWavformType.RefWavformEight);

                IsOccupyR1 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR2 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR3 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR4 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR5 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR6 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR7 = LangugeConvertor.GetValue("Unoccupied");
                IsOccupyR8 = LangugeConvertor.GetValue("Unoccupied");

                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
            
        }

        #endregion

    }
}
